package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.GcgWsjdShenpiXq;
import cn.stylefeng.guns.sys.modular.system.mapper.GcgWsjdShenpiXqMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.GcgWsjdShenpiXqParam;
import cn.stylefeng.guns.sys.modular.system.model.result.GcgWsjdShenpiXqResult;
import  cn.stylefeng.guns.sys.modular.system.service.GcgWsjdShenpiXqService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 网上建店审批详情 服务实现类
 * </p>
 *
 * @author liuy
 * @since 2021-05-18
 */
@Service
public class GcgWsjdShenpiXqServiceImpl extends ServiceImpl<GcgWsjdShenpiXqMapper, GcgWsjdShenpiXq> implements GcgWsjdShenpiXqService {

    @Override
    public void add(GcgWsjdShenpiXqParam param){
        GcgWsjdShenpiXq entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(GcgWsjdShenpiXqParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(GcgWsjdShenpiXqParam param){
        GcgWsjdShenpiXq oldEntity = getOldEntity(param);
        GcgWsjdShenpiXq newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public GcgWsjdShenpiXqResult findBySpec(GcgWsjdShenpiXqParam param){
        return null;
    }

    @Override
    public List<GcgWsjdShenpiXqResult> findListBySpec(GcgWsjdShenpiXqParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(GcgWsjdShenpiXqParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(GcgWsjdShenpiXqParam param){
        return param.getGcgWsjdShenpiXqId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private GcgWsjdShenpiXq getOldEntity(GcgWsjdShenpiXqParam param) {
        return this.getById(getKey(param));
    }

    private GcgWsjdShenpiXq getEntity(GcgWsjdShenpiXqParam param) {
        GcgWsjdShenpiXq entity = new GcgWsjdShenpiXq();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
